package com.byyy.ccts.core.utils;

import com.byyy.ccts.core.base.ILogBase;
import com.google.common.util.concurrent.ThreadFactoryBuilder;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author lyb
 * @date 2021-12-13
 * @description 线程池
 */
public class ThreadPoolUtils implements ILogBase {

    private static ExecutorService pool = new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors(),
            Runtime.getRuntime().availableProcessors() * 2,
            0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(1024), new ThreadFactoryBuilder()
            .setNameFormat("thread-pool-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy());

    /**
     * 通用线程池执行方法
     * @param runnable
     */
    public static void execute(Runnable runnable) {
        pool.execute(runnable);
    }

}
